/**
 * Copyright (c) 2015-2030 by Beijing Yanlight Co., Ltd.
 * All rights reserved.
 */
package com.yanlight.util;

import java.util.Date;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import com.yanlight.Constants;

/**
 * 
 *
 * @author haolw
 * @time 2017/07/14
 */
public abstract class DateTimeUtil {

	/**
	 * yyyy-MM-dd HH:mm:ss
	 * 
	 * @return
	 */
	public static String getNowTime() {
		return DateTime.now().toString(Constants.format1);
	}

	/**
	 * yyyy-MM-dd 00:00:00
	 * 
	 * @return
	 */
	public static String getNowDayBegin() {
		return DateTime.now().toString(Constants.format6);
	}

	/**
	 * yyyy-MM-dd 23:59:59
	 * 
	 * @return
	 */
	public static String getNowDayEnd() {
		return DateTime.now().toString(Constants.format7);
	}

	/**
	 * yyyy-MM-dd 00:00:00
	 * 
	 * @return
	 */
	public static String getNowTimeZero() {
		return DateTime.now().toString(Constants.format6);
	}

	/**
	 * yyyyMMddHHmmss
	 * 
	 * @return
	 */
	public static String getCompactNowTime() {
		return DateTime.now().toString(Constants.format2);
	}

	/**
	 * yyyyMMddHHmmssSSS
	 * 
	 * @return
	 */
	public static String getCompactMillNowTime() {
		return DateTime.now().toString(Constants.format3);
	}

	/**
	 * yyyy-MM-dd HH:mm:ss to yyyy.MM.dd
	 * 
	 * @param time
	 * @return
	 */
	public static String converToDayTime(String time) {
		DateTimeFormatter formatter = DateTimeFormat.forPattern(Constants.format1);
		DateTime dateTime = DateTime.parse(time, formatter);
		return dateTime.toString(Constants.format4);
	}

	/**
	 * Date to yyyy.MM.dd
	 * 
	 * @param date
	 * @return
	 */
	public static String converToDayTime(Date date) {
		return new DateTime(date).toString(Constants.format4);
	}

	/**
	 * time,formatSource to formatTarget
	 * 
	 * @param time
	 * @return
	 */
	public static String conver(String time, String formatSource, String formatTarget) {
		DateTimeFormatter formatter = DateTimeFormat.forPattern(formatSource);
		DateTime dateTime = DateTime.parse(time, formatter);
		return dateTime.toString(formatTarget);
	}

	/**
	 * 得到当前年份
	 * 
	 * @return
	 */
	public static String getNowYear() {
		return String.valueOf(new DateTime().getYear());
	}

	/**
	 * 得到当前月份
	 * 
	 * @return
	 */
	public static String getNowMonth() {
		return String.valueOf(new DateTime().getMonthOfYear());
	}

	/**
	 * yyyy-MM-dd HH:mm:ss
	 * 
	 * @param time
	 * @return
	 */
	public static boolean checkExpire(String time) {
		DateTimeFormatter formatter = DateTimeFormat.forPattern(Constants.format1);
		DateTime dateTime = DateTime.parse(time, formatter);
		return dateTime.isBeforeNow();
	}

	/**
	 * yyyy-MM-dd HH:mm:ss
	 * 
	 * @param second
	 * @return
	 */
	public static String plusSecond(Integer second) {
		return DateTime.now().plusSeconds(second).toString(Constants.format1);
	}

	/**
	 * yyyy-MM-dd HH:mm:ss
	 * 
	 * @param month
	 * @return
	 */
	public static String plusMonth(Integer month) {
		return DateTime.now().plusMonths(month).toString(Constants.format1);
	}

	/**
	 * yyyy-MM-dd HH:mm:ss
	 * 
	 * @param month
	 * @return
	 */
	public static String plusMonth(String time, Integer month) {
		DateTimeFormatter formatter = DateTimeFormat.forPattern(Constants.format1);
		DateTime dateTime = DateTime.parse(time, formatter);
		return dateTime.plusMonths(month).toString(Constants.format1);
	}

	/**
	 * yyyy-MM-dd HH:mm:ss
	 * 
	 * @param seconds
	 * @return
	 */
	public static String plusSeconds(Integer seconds) {
		return DateTime.now().plusSeconds(seconds).toString(Constants.format1);
	}

	/**
	 * yyyy-MM-dd HH:mm:ss
	 * 
	 * @param seconds
	 * @return
	 */
	public static String minusSeconds(Integer seconds) {
		return DateTime.now().minusSeconds(seconds).toString(Constants.format1);
	}

	/**
	 * yyyy-MM-dd
	 * 
	 * @param seconds
	 * @return
	 */
	public static String plusDayYMD(Integer day) {
		return DateTime.now().plusDays(day).toString(Constants.format5);
	}

	/**
	 * yyyy-MM-dd
	 * 
	 * @param seconds
	 * @return
	 */
	public static String minusDayYMD(Integer day) {
		return DateTime.now().minusDays(day).toString(Constants.format5);
	}

	/**
	 * yyyy-MM-dd 00:00:00
	 * 
	 * @param seconds
	 * @return
	 */
	public static String minusDayZero(Integer day) {
		return DateTime.now().minusDays(day).toString(Constants.format6);
	}

}
